/*! @file searchdlg.cpp
  * @brief implementation of SearchDlg Class
  * @author AK
  * @date 01.07.2012
  */

#include "searchdlg.h"

/*! @brief SearchDlg Constructor
 * @callgraph
 * @callergraph
 *
 * @param st QString: Searchterms
 * @param from QDate: first entry in db
 * @param to QDate: last entry in db
 * @param *parent QWidget
 */
SearchDlg::SearchDlg(QString column,
                     QString st,
                     QDate from = QDate::currentDate(),
                     QDate to = QDate::currentDate(),
                     QWidget *parent) :
    QDialog(parent)
{
    setupUi(this);
    connect(pushButtonSearchOk, SIGNAL(clicked()),
            this, SLOT(on_okClicked()));

    lineEditSearch->setText(st);
    timeFormat = "yyyy'-'MM'-'dd";
    header = column;
    dateEditFrom->setDate(from);
    dateEditTo->setDate(to);
    dateEditFrom->setEnabled(true);
    dateEditTo->setEnabled(true);

}

/** @brief SearchDlg Destructor
 * @callgraph
 * @callergraph
 */
SearchDlg::~SearchDlg()
{
    //    delete ui;
}

/** @brief gets items from Dialog
 * emits accepted(bool, QString, QDate, QDate)
 * @callgraph
 * @callergraph
 *
 */
void SearchDlg::on_okClicked()
{
    bool doDate = false;

    QString st = lineEditSearch->text();

    if(checkBoxFrom->checkState()) {
        doDate = true;
    }
    if(checkBoxTo->checkState()) {
        doDate = true;
    }

    QDate f = dateEditFrom->date();
    QDate t = dateEditTo->date();

    Q_EMIT accepted(header, doDate, st, f, t);
}
